package org.eclipse.epsilon.emc.rdbms.core.unitesting.blackbox;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import org.eclipse.epsilon.emc.rdbms.core.imodel.DBReflexiveModel;
import org.eclipse.epsilon.emc.rdbms.core.imodel.DBReflexiveModelElement;
import org.eclipse.epsilon.emc.rdbms.core.persistancebroker.PersistanceBroker;
import org.eclipse.epsilon.emc.rdbms.core.persistancemechanism.RelationalDatabase;
import org.eclipse.epsilon.emc.rdbms.core.persistanttransaction.PersistanceTransaction;
import org.eclipse.epsilon.eol.EolModule;
import org.eclipse.epsilon.eol.exceptions.EolRuntimeException;
import org.eclipse.epsilon.eol.exceptions.models.EolModelElementTypeNotFoundException;
import org.eclipse.epsilon.eol.exceptions.models.EolModelLoadingException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


public class JUnit_BlackBox_EOL_Testing 
{
String modelString="";
PersistanceBroker  pb = new PersistanceBroker();
RelationalDatabase Connection = null;
DBReflexiveModel rModel = new DBReflexiveModel();  //Create a new model.

	
@Before public void Run_Pre_Test()
{
	//Reset the underlying database details.
	Connection = pb.connectTo();
	Connection.db_setup("C:\\config.sql");	
	rModel.setName("EPSILON"); //Set the Model Name
}

/** These are the JUnit Tests to test the creation of a new element in an existing type**/

/** This is a JUnit test.
 *  This is to test that we are able to add a new customer to the database with the correct details.
**/
@Test public void BasicEOL_CreateNewCustomerElement()
{	
	try 
	{		
		assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("CUSTOMER").size());
		modelString = ("var a = new CUSTOMER;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.CUSTOMER WHERE CUSTOMERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The CustomerID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The firstname should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The surname should be equal to null",null,QuereyResult.getString(3));
			assertEquals("The AddressID should be equal to 0",0,QuereyResult.getInt(4));			
		}
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("CUSTOMER");
		assertEquals("The element should be of type CUSTOMER","CUSTOMER",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of","6",(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of firstName",null,(((DBReflexiveModelElement) element).getProps().get("FIRSTNAME")));
		assertEquals("The element should not have a property of surname",null,(((DBReflexiveModelElement) element).getProps().get("SURNAME")));
		assertEquals("The element should not have a property of addressID",null,(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}

@Test public void BasicEOL_CreateNewAddressElement()
{
	try 
	{		
		assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
		modelString = ("var a = new ADDRESS;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ADDRESS WHERE ADDRESSID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The AddressID should be equal to 4",4,QuereyResult.getInt(1));
			assertEquals("The Street should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The Number should be equal to null",null,QuereyResult.getString(3));
			assertEquals("The PostCode should be equal to 0",0,QuereyResult.getInt(4));
			assertEquals("The Country should be equal to 0",0,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ADDRESS");
		assertEquals("The element should be of type ADDRESS","ADDRESS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 5","5",(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
		assertEquals("The element should not have a property of Street",null,(((DBReflexiveModelElement) element).getProps().get("STREET")));
		assertEquals("The element should not have a property of number",null,(((DBReflexiveModelElement) element).getProps().get("NUMBER")));
		assertEquals("The element should not have a property of postcode",null,(((DBReflexiveModelElement) element).getProps().get("POSTCODE")));
		assertEquals("The element should not have a property of country",null,(((DBReflexiveModelElement) element).getProps().get("COUNTRY")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}

@Test public void BasicEOL_CreateNewProductElement()
{
	try 
	{		
		assertEquals("The number of records should be 7 before insert",7,rModel.getAllOfType("PRODUCT").size());
		modelString = ("var a = new PRODUCT;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 8 after insert",8,rModel.getAllOfType("PRODUCT").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.PRODUCT WHERE PRODUCTID=7";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The productId should be equal to 7",7,QuereyResult.getInt(1));
			assertEquals("The name should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The unitPrice should be equal to null",null,QuereyResult.getDate(3));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("PRODUCT");
		assertEquals("The element should be of type PRODUCT","PRODUCT",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 8","8",(((DBReflexiveModelElement) element).getProps().get("PRODUCTID")));
		assertEquals("The element should not have a property of name",null,(((DBReflexiveModelElement) element).getProps().get("NAME")));
		assertEquals("The element should not have a property of unitPrice",null,(((DBReflexiveModelElement) element).getProps().get("UNITPRICE")));
    } 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_CreateNewOrdersElement()
{
	try 
	{		
		assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
		modelString = ("var a = new ORDERS;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());

		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERS WHERE ORDERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The customerID should be equal to null",0,QuereyResult.getInt(2));
			assertEquals("The dateIssued should be equal to null",null,QuereyResult.getDate(3));
			assertEquals("The devlivered should be equal to 0",false,QuereyResult.getBoolean(4));
			assertEquals("The deliveryAddress should be equal to 0",0,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERS");
		assertEquals("The element should be of type ORDERS","ORDERS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 6","6",(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of customerID",null,(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of dateIssued",null,(((DBReflexiveModelElement) element).getProps().get("DATEISSUED")));
		assertEquals("The element should not have a property of delivered",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERED")));
		assertEquals("The element should not have a property of deliveryAddress",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERYADDRESS")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}

@Test public void BasicEOL_CreateNewOrdersDetailsElement()
{
	try 
	{		
		assertEquals("The number of records should be 11 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
		modelString = ("var a = new ORDERSDETAIL;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 12 after insert",12,rModel.getAllOfType("ORDERSDETAIL").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERSDETAIL WHERE ORDERDETAILID=11";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderDetailID should be equal to 11",11,QuereyResult.getInt(1));
			assertEquals("The orderID should be equal to null",0,QuereyResult.getInt(2));
			assertEquals("The productID should be equal to null",0,QuereyResult.getInt(3));
			assertEquals("The quantity should be equal to 0",0,QuereyResult.getInt(4));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERSDETAIL");
		assertEquals("The element should be of type ORDERSDETAIL","ORDERSDETAIL",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 12","12",(((DBReflexiveModelElement) element).getProps().get("ORDERDETAILID")));
		assertEquals("The element should not have a property of orderID",null,(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of productId",null,(((DBReflexiveModelElement) element).getProps().get("PRODUCTID")));
		assertEquals("The element should not have a property of quantity",null,(((DBReflexiveModelElement) element).getProps().get("QUANTITY")));
		} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_CreateNewWrongElement()
{
	try 
	{		
		modelString = ("var a = new BOB;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		fail("should throw an Exception");
	}		
	catch (EolModelElementTypeNotFoundException e) 
	{
	    e.printStackTrace();	
	    fail("should not throw this Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw this Exception");
	} 
	catch (Exception e)
	{
		//This should throw this exception.
	}
}

/** These are the JUnit Tests to test the update of a existing element in an existing type**/

/** This is a JUnit test.
 *  This is to test that we are able to update a new customer to the database with the correct details.
**/
@Test public void BasicEOL_UpdateCustomerfirstName()
{
	try 
	{		
		assertEquals("The number of records should be 5 before the test ",5,rModel.getAllOfType("CUSTOMER").size());
		modelString = ("var a = new CUSTOMER;a.firstname='newfirstname';");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
		//Now see if it has successfully added the correct details to the database.
	
		String statement = "SELECT * FROM EPSILON.EPSILON.CUSTOMER where CUSTOMERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The CustomerID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The firstname should be equal to newUser","newfirstname",QuereyResult.getString(2));
			assertEquals("The surname should be equal to null",null,QuereyResult.getString(3));
			assertEquals("The AddressID should be equal to 0",0,QuereyResult.getInt(4));			
		}
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("CUSTOMER");
		assertEquals("The element should be of type CUSTOMER","CUSTOMER",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of","6",(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of firstName",null,(((DBReflexiveModelElement) element).getProps().get("FIRSTNAME")));
		assertEquals("The element should not have a property of lastname",null,(((DBReflexiveModelElement) element).getProps().get("LASTNAME")));
		assertEquals("The element should not have a property of addressID",null,(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
	}
		catch (EolModelElementTypeNotFoundException e) 
	{
	    e.printStackTrace();	
	    fail("should not throw this Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw this Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw this Exception");
	}
}

@Test public void BasicEOL_UpdateCustomerlastName()
{
	try 
	{		
		assertEquals("The number of records should be 5 before the test ",5,rModel.getAllOfType("CUSTOMER").size());
		modelString = ("var a = new CUSTOMER;a.lastname='newlastname';");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
		//Now see if it has successfully added the correct details to the database.
	
		String statement = "SELECT * FROM EPSILON.EPSILON.CUSTOMER where CUSTOMERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The CustomerID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The firstname should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The surname should be equal to newlastname","newlastname",QuereyResult.getString(3));
			assertEquals("The AddressID should be equal to 0",0,QuereyResult.getInt(4));			
		}
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("CUSTOMER");
		assertEquals("The element should be of type CUSTOMER","CUSTOMER",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of","6",(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of firstName",null,(((DBReflexiveModelElement) element).getProps().get("FIRSTNAME")));
		assertEquals("The element should not have a property of lastname",null,(((DBReflexiveModelElement) element).getProps().get("LASTNAME")));
		assertEquals("The element should not have a property of addressID",null,(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
	}
		catch (EolModelElementTypeNotFoundException e) 
	{
	    e.printStackTrace();	
	    fail("should not throw this Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw this Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw this Exception");
	}	
}

@Test public void BasicEOL_UpdateCustomerAddressId()
{
	try 
	{		
		assertEquals("The number of records should be 5 before the test ",5,rModel.getAllOfType("CUSTOMER").size());
		modelString = ("var a = new CUSTOMER;a.addressID=2;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
		//Now see if it has successfully added the correct details to the database.
	
		String statement = "SELECT * FROM EPSILON.EPSILON.CUSTOMER where CUSTOMERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The CustomerID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The firstname should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The surname should be equal to null",null,QuereyResult.getString(3));
			assertEquals("The AddressID should be equal to 0",2,QuereyResult.getInt(4));			
		}
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("CUSTOMER");
		assertEquals("The element should be of type CUSTOMER","CUSTOMER",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of","6",(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of firstName",null,(((DBReflexiveModelElement) element).getProps().get("FIRSTNAME")));
		assertEquals("The element should not have a property of lastname",null,(((DBReflexiveModelElement) element).getProps().get("LASTNAME")));
		assertEquals("The element should not have a property of addressID",null,(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
	}
		catch (EolModelElementTypeNotFoundException e) 
	{
	    e.printStackTrace();	
	    fail("should not throw this Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw this Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw this Exception");
	}	
}

@Test public void BasicEOL_UpdateCustomercustomerId()
{
//We should not be able to update the customerID in the system. The RI of the database should fail	
	try 
	{		
		assertEquals("The number of records should be 5 before the test ",5,rModel.getAllOfType("CUSTOMER").size());
		modelString = ("var a = new CUSTOMER;a.customerId=99999;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
		//Now see if it has successfully added the correct details to the database.
	
		String statement = "SELECT * FROM EPSILON.EPSILON.CUSTOMER where CUSTOMERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The CustomerID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The firstname should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The surname should be equal to null",null,QuereyResult.getString(3));
			assertEquals("The AddressID should be equal to 0",2,QuereyResult.getInt(4));			
		}
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("CUSTOMER");
		assertEquals("The element should be of type CUSTOMER","CUSTOMER",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of","5",(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));  //RI Should prevent this
		assertEquals("The element should not have a property of firstName",null,(((DBReflexiveModelElement) element).getProps().get("FIRSTNAME")));
		assertEquals("The element should not have a property of lastname",null,(((DBReflexiveModelElement) element).getProps().get("LASTNAME")));
		assertEquals("The element should not have a property of addressID",null,(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
	}
		catch (EolModelElementTypeNotFoundException e) 
	{
	    e.printStackTrace();	
	    fail("should not throw this Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw this Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw this Exception");
	}
	
}


@Test public void BasicEOL_UpdateAddressStreet()
{
	try 
	{		
		
		assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
		modelString = ("var a = new ADDRESS;a.street='newStreet';");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ADDRESS WHERE ADDRESSID=4";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The AddressID should be equal to 4",4,QuereyResult.getInt(1));
			assertEquals("The Street should be equal to newStreet","newStreet",QuereyResult.getString(2));
			assertEquals("The Number should be equal to null",null,QuereyResult.getString(3));
			assertEquals("The PostCode should be equal to 0",0,QuereyResult.getInt(4));
			assertEquals("The Country should be equal to 0",0,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ADDRESS");
		assertEquals("The element should be of type ADDRESS","ADDRESS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 5","5",(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
		assertEquals("The element should not have a property of Street",null,(((DBReflexiveModelElement) element).getProps().get("STREET")));
		assertEquals("The element should not have a property of number",null,(((DBReflexiveModelElement) element).getProps().get("NUMBER")));
		assertEquals("The element should not have a property of postcode",null,(((DBReflexiveModelElement) element).getProps().get("POSTCODE")));
		assertEquals("The element should not have a property of country",null,(((DBReflexiveModelElement) element).getProps().get("COUNTRY")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}



@Test public void BasicEOL_UpdateAddressNumber()
{
	try 
	{		
		assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
		modelString = ("var a = new ADDRESS;a.number='88';");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ADDRESS WHERE ADDRESSID=4";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The AddressID should be equal to 4",4,QuereyResult.getInt(1));
			assertEquals("The Street should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The Number should be equal to 88",88,QuereyResult.getInt(3));
			assertEquals("The PostCode should be equal to 0",0,QuereyResult.getInt(4));
			assertEquals("The Country should be equal to 0",0,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ADDRESS");
		assertEquals("The element should be of type ADDRESS","ADDRESS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 5","5",(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
		assertEquals("The element should not have a property of Street",null,(((DBReflexiveModelElement) element).getProps().get("STREET")));
		assertEquals("The element should not have a property of number",null,(((DBReflexiveModelElement) element).getProps().get("NUMBER")));
		assertEquals("The element should not have a property of postcode",null,(((DBReflexiveModelElement) element).getProps().get("POSTCODE")));
		assertEquals("The element should not have a property of country",null,(((DBReflexiveModelElement) element).getProps().get("COUNTRY")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}	

@Test public void BasicEOL_UpdateAddressPostCode()
{
	try 
	{		
		assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
		modelString = ("var a = new ADDRESS;a.postcode='newPostcode';");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ADDRESS WHERE ADDRESSID=4";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The AddressID should be equal to 4",4,QuereyResult.getInt(1));
			assertEquals("The Street should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The Number should be equal to null",null,QuereyResult.getString(3));
			assertEquals("The PostCode should be equal to newpostcode","newPostcode",QuereyResult.getString(4));
			assertEquals("The Country should be equal to 0",0,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ADDRESS");
		assertEquals("The element should be of type ADDRESS","ADDRESS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 5","5",(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
		assertEquals("The element should not have a property of Street",null,(((DBReflexiveModelElement) element).getProps().get("STREET")));
		assertEquals("The element should not have a property of number",null,(((DBReflexiveModelElement) element).getProps().get("NUMBER")));
		assertEquals("The element should not have a property of postcode",null,(((DBReflexiveModelElement) element).getProps().get("POSTCODE")));
		assertEquals("The element should not have a property of country",null,(((DBReflexiveModelElement) element).getProps().get("COUNTRY")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}	

@Test public void BasicEOL_UpdateAddressCountry()
{
	try 
	{		
		assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
		modelString = ("var a = new ADDRESS;a.country='newCountry';");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ADDRESS WHERE ADDRESSID=4";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The AddressID should be equal to 4",4,QuereyResult.getInt(1));
			assertEquals("The Street should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The Number should be equal to null",null,QuereyResult.getString(3));
			assertEquals("The PostCode should be equal to null",null,QuereyResult.getString(4));
			assertEquals("The Country should be equal to newCountry","newCountry",QuereyResult.getString(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ADDRESS");
		assertEquals("The element should be of type ADDRESS","ADDRESS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 5","5",(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
		assertEquals("The element should not have a property of Street",null,(((DBReflexiveModelElement) element).getProps().get("STREET")));
		assertEquals("The element should not have a property of number",null,(((DBReflexiveModelElement) element).getProps().get("NUMBER")));
		assertEquals("The element should not have a property of postcode",null,(((DBReflexiveModelElement) element).getProps().get("POSTCODE")));
		assertEquals("The element should not have a property of country",null,(((DBReflexiveModelElement) element).getProps().get("COUNTRY")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}	

@Test public void BasicEOL_UpdateAddressAddressId()
{
	try 
	{		
		assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
		modelString = ("var a = new ADDRESS;a.addressId=9999;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ADDRESS WHERE ADDRESSID=9999";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		Connection.printResultSet("",QuereyResult );
		while (QuereyResult.next())
		{
			assertEquals("The AddressID should be equal to 4",4,QuereyResult.getInt(1));
			assertEquals("The Street should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The Number should be equal to null",null,QuereyResult.getString(3));
			assertEquals("The PostCode should be equal to null",null,QuereyResult.getString(4));
			assertEquals("The Country should be equal to nully",null,QuereyResult.getString(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ADDRESS");
		assertEquals("The element should be of type ADDRESS","ADDRESS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 5","5",(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
		assertEquals("The element should not have a property of Street",null,(((DBReflexiveModelElement) element).getProps().get("STREET")));
		assertEquals("The element should not have a property of number",null,(((DBReflexiveModelElement) element).getProps().get("NUMBER")));
		assertEquals("The element should not have a property of postcode",null,(((DBReflexiveModelElement) element).getProps().get("POSTCODE")));
		assertEquals("The element should not have a property of country",null,(((DBReflexiveModelElement) element).getProps().get("COUNTRY")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}	
		
@Test public void BasicEOL_UpdateProductName()
{
	try 
	{		
		assertEquals("The number of records should be 7 before insert",7,rModel.getAllOfType("PRODUCT").size());
		modelString = ("var a = new PRODUCT;a.name='newProductName';");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 8 after insert",8,rModel.getAllOfType("PRODUCT").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.PRODUCT WHERE PRODUCTID=7";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The productId should be equal to 7",7,QuereyResult.getInt(1));
			assertEquals("The name should be equal to newProductName","newProductName",QuereyResult.getString(2));
			assertEquals("The unitPrice should be equal to null",null,QuereyResult.getString(3));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("PRODUCT");
		assertEquals("The element should be of type PRODUCT","PRODUCT",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 8","8",(((DBReflexiveModelElement) element).getProps().get("PRODUCTID")));
		assertEquals("The element should not have a property of name",null,(((DBReflexiveModelElement) element).getProps().get("NAME")));
		assertEquals("The element should not have a property of unitPrice",null,(((DBReflexiveModelElement) element).getProps().get("UNITPRICE")));
    } 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}
	
@Test public void BasicEOL_UpdateProductUnitPrice()
{
	try 
	{		
		assertEquals("The number of records should be 7 before insert",7,rModel.getAllOfType("PRODUCT").size());
		modelString = ("var a = new PRODUCT;a.UnitPrice=9.99;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 8 after insert",8,rModel.getAllOfType("PRODUCT").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.PRODUCT WHERE PRODUCTID=7";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The productId should be equal to 7",7,QuereyResult.getInt(1));
			assertEquals("The name should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The unitPrice should be equal to 9.99","9.99",QuereyResult.getString(3));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("PRODUCT");
		assertEquals("The element should be of type PRODUCT","PRODUCT",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 8","8",(((DBReflexiveModelElement) element).getProps().get("PRODUCTID")));
		assertEquals("The element should not have a property of name",null,(((DBReflexiveModelElement) element).getProps().get("NAME")));
		assertEquals("The element should not have a property of unitPrice",null,(((DBReflexiveModelElement) element).getProps().get("UNITPRICE")));
    } 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}		
}

@Test public void BasicEOL_UpdateProductId()
{
	try 
	{		
		assertEquals("The number of records should be 7 before insert",7,rModel.getAllOfType("PRODUCT").size());
		modelString = ("var a = new PRODUCT;a.ProductId=9999;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 8 after insert",8,rModel.getAllOfType("PRODUCT").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.PRODUCT WHERE PRODUCTID=7";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The productId should be equal to 7",7,QuereyResult.getInt(1));
			assertEquals("The name should be equal to null",null,QuereyResult.getString(2));
			assertEquals("The unitPrice should be equal to null",null,QuereyResult.getString(3));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("PRODUCT");
		assertEquals("The element should be of type PRODUCT","PRODUCT",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 8","8",(((DBReflexiveModelElement) element).getProps().get("PRODUCTID")));
		assertEquals("The element should not have a property of name",null,(((DBReflexiveModelElement) element).getProps().get("NAME")));
		assertEquals("The element should not have a property of unitPrice",null,(((DBReflexiveModelElement) element).getProps().get("UNITPRICE")));
    } 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}			
}

@Test public void BasicEOL_UpdateOrdersCustomerId()
{
	try 
	{		
		assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
		modelString = ("var a = new ORDERS;a.CustomerId=1;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());

		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERS WHERE ORDERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The customerID should be equal to 1",1,QuereyResult.getInt(2));
			assertEquals("The dateIssued should be equal to null",null,QuereyResult.getDate(3));
			assertEquals("The devlivered should be equal to 0",false,QuereyResult.getBoolean(4));
			assertEquals("The deliveryAddress should be equal to 0",0,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERS");
		assertEquals("The element should be of type ORDERS","ORDERS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 6","6",(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of customerID",null,(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of dateIssued",null,(((DBReflexiveModelElement) element).getProps().get("DATEISSUED")));
		assertEquals("The element should not have a property of delivered",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERED")));
		assertEquals("The element should not have a property of deliveryAddress",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERYADDRESS")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
	
}

@Test public void BasicEOL_UpdateOrdersDateIssued()
{
	try 
	{		
		assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
		modelString = ("var a = new ORDERS;a.DateIssued='2012-08-01 07:34:15.287';");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());

		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERS WHERE ORDERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The customerID should be equal to null",0,QuereyResult.getInt(2));
			assertEquals("The dateIssued should be equal to 2012-08-01 07:34:15.287","2012-08-01 07:34:15.287",QuereyResult.getTimestamp(3).toString());
			assertEquals("The devlivered should be equal to 0",false,QuereyResult.getBoolean(4));
			assertEquals("The deliveryAddress should be equal to 0",0,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERS");
		assertEquals("The element should be of type ORDERS","ORDERS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 6","6",(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of customerID",null,(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of dateIssued",null,(((DBReflexiveModelElement) element).getProps().get("DATEISSUED")));
		assertEquals("The element should not have a property of delivered",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERED")));
		assertEquals("The element should not have a property of deliveryAddress",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERYADDRESS")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_UpdateOrdersdelivered()
{
	try 
	{		
		assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
		modelString = ("var a = new ORDERS;a.delivered='true';");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());

		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERS WHERE ORDERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The customerID should be equal to null",0,QuereyResult.getInt(2));
			assertEquals("The dateIssued should be equal to null",null,QuereyResult.getDate(3));
			assertEquals("The devlivered should be equal to 0",true,QuereyResult.getBoolean(4));
			assertEquals("The deliveryAddress should be equal to 0",0,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERS");
		assertEquals("The element should be of type ORDERS","ORDERS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 6","6",(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of customerID",null,(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of dateIssued",null,(((DBReflexiveModelElement) element).getProps().get("DATEISSUED")));
		assertEquals("The element should not have a property of delivered",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERED")));
		assertEquals("The element should not have a property of deliveryAddress",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERYADDRESS")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_UpdateOrdersDeliveryAddressId()
{
	try 
	{		
		assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
		modelString = ("var a = new ORDERS;a.DeliveryAddressId=1;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());

		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERS WHERE ORDERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The customerID should be equal to null",0,QuereyResult.getInt(2));
			assertEquals("The dateIssued should be equal to null",null,QuereyResult.getDate(3));
			assertEquals("The devlivered should be equal to 0",false,QuereyResult.getBoolean(4));
			assertEquals("The deliveryAddress should be equal to 1",1,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERS");
		assertEquals("The element should be of type ORDERS","ORDERS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 6","6",(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of customerID",null,(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of dateIssued",null,(((DBReflexiveModelElement) element).getProps().get("DATEISSUED")));
		assertEquals("The element should not have a property of delivered",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERED")));
		assertEquals("The element should not have a property of deliveryAddress",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERYADDRESS")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_UpdateOrdersOrdersId()
{
	try 
	{		
		assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
		modelString = ("var a = new ORDERS;a.OrderId=9999;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());

		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERS WHERE ORDERID=5";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderID should be equal to 5",5,QuereyResult.getInt(1));
			assertEquals("The customerID should be equal to null",0,QuereyResult.getInt(2));
			assertEquals("The dateIssued should be equal to null",null,QuereyResult.getDate(3));
			assertEquals("The devlivered should be equal to 0",false,QuereyResult.getBoolean(4));
			assertEquals("The deliveryAddress should be equal to 0",0,QuereyResult.getInt(5));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERS");
		assertEquals("The element should be of type ORDERS","ORDERS",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 6","6",(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of customerID",null,(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
		assertEquals("The element should not have a property of dateIssued",null,(((DBReflexiveModelElement) element).getProps().get("DATEISSUED")));
		assertEquals("The element should not have a property of delivered",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERED")));
		assertEquals("The element should not have a property of deliveryAddress",null,(((DBReflexiveModelElement) element).getProps().get("DELIVERYADDRESS")));
	} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}	


@Test public void BasicEOL_UpdateOrdersDetailOrderId()
{
	try 
	{		
		assertEquals("The number of records should be 11 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
		modelString = ("var a = new ORDERSDETAIL;a.orderId=1;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 12 after insert",12,rModel.getAllOfType("ORDERSDETAIL").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERSDETAIL WHERE ORDERDETAILID=11";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderDetailID should be equal to 11",11,QuereyResult.getInt(1));
			assertEquals("The orderID should be equal to null",1,QuereyResult.getInt(2));
			assertEquals("The productID should be equal to null",0,QuereyResult.getInt(3));
			assertEquals("The quantity should be equal to 0",0,QuereyResult.getInt(4));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERSDETAIL");
		assertEquals("The element should be of type ORDERSDETAIL","ORDERSDETAIL",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 12","12",(((DBReflexiveModelElement) element).getProps().get("ORDERDETAILID")));
		assertEquals("The element should not have a property of orderID",null,(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of productId",null,(((DBReflexiveModelElement) element).getProps().get("PRODUCTID")));
		assertEquals("The element should not have a property of quantity",null,(((DBReflexiveModelElement) element).getProps().get("QUANTITY")));
		} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
	
	
}

@Test public void BasicEOL_UpdateOrdersDetailProductId()
{
	try 
	{		
		assertEquals("The number of records should be 11 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
		modelString = ("var a = new ORDERSDETAIL;a.ProductId=1;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 12 after insert",12,rModel.getAllOfType("ORDERSDETAIL").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERSDETAIL WHERE ORDERDETAILID=11";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderDetailID should be equal to 11",11,QuereyResult.getInt(1));
			assertEquals("The orderID should be equal to null",0,QuereyResult.getInt(2));
			assertEquals("The productID should be equal to 1",1,QuereyResult.getInt(3));
			assertEquals("The quantity should be equal to 0",0,QuereyResult.getInt(4));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERSDETAIL");
		assertEquals("The element should be of type ORDERSDETAIL","ORDERSDETAIL",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 12","12",(((DBReflexiveModelElement) element).getProps().get("ORDERDETAILID")));
		assertEquals("The element should not have a property of orderID",null,(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of productId",null,(((DBReflexiveModelElement) element).getProps().get("PRODUCTID")));
		assertEquals("The element should not have a property of quantity",null,(((DBReflexiveModelElement) element).getProps().get("QUANTITY")));
		} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	

}

@Test public void BasicEOL_UpdateOrdersDetailQuantity()
{
	try 
	{		
		assertEquals("The number of records should be 11 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
		modelString = ("var a = new ORDERSDETAIL;a.Quantity=10;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 12 after insert",12,rModel.getAllOfType("ORDERSDETAIL").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERSDETAIL WHERE ORDERDETAILID=11";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderDetailID should be equal to 11",11,QuereyResult.getInt(1));
			assertEquals("The orderID should be equal to null",0,QuereyResult.getInt(2));
			assertEquals("The productID should be equal to null",0,QuereyResult.getInt(3));
			assertEquals("The quantity should be equal to 10",10,QuereyResult.getInt(4));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERSDETAIL");
		assertEquals("The element should be of type ORDERSDETAIL","ORDERSDETAIL",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 12","12",(((DBReflexiveModelElement) element).getProps().get("ORDERDETAILID")));
		assertEquals("The element should not have a property of orderID",null,(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of productId",null,(((DBReflexiveModelElement) element).getProps().get("PRODUCTID")));
		assertEquals("The element should not have a property of quantity",null,(((DBReflexiveModelElement) element).getProps().get("QUANTITY")));
		} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	

	
}

@Test public void BasicEOL_UpdateOrdersDetailOrdersDetailId()
{
	try 
	{		
		assertEquals("The number of records should be 11 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
		modelString = ("var a = new ORDERSDETAIL;a.OrderdDetailId=9999;");
		rModel.load();
		EolModule module = new EolModule(); 
		module.parse(modelString);
		module.getContext().getModelRepository().addModel(rModel);
		Object returnValue = module.execute();
		assertEquals("The number of records should be 12 after insert",12,rModel.getAllOfType("ORDERSDETAIL").size());

		
		//Now see if it has successfully added the correct details to the database.
		String statement = "SELECT * FROM EPSILON.EPSILON.ORDERSDETAIL WHERE ORDERDETAILID=11";
		Statement stmt = Connection.open().createStatement();
		ResultSet QuereyResult = stmt.executeQuery(statement);
		while (QuereyResult.next())
		{
			assertEquals("The orderDetailID should be equal to 11",11,QuereyResult.getInt(1));
			assertEquals("The orderID should be equal to null",0,QuereyResult.getInt(2));
			assertEquals("The productID should be equal to null",0,QuereyResult.getInt(3));
			assertEquals("The quantity should be equal to 0",0,QuereyResult.getInt(4));
		}
		
		//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
		Object element =  rModel.createInstance("ORDERSDETAIL");
		assertEquals("The element should be of type ORDERSDETAIL","ORDERSDETAIL",(((DBReflexiveModelElement) element).getType()));
		assertEquals("The element should have an element ID of 12","12",(((DBReflexiveModelElement) element).getProps().get("ORDERDETAILID")));
		assertEquals("The element should not have a property of orderID",null,(((DBReflexiveModelElement) element).getProps().get("ORDERID")));
		assertEquals("The element should not have a property of productId",null,(((DBReflexiveModelElement) element).getProps().get("PRODUCTID")));
		assertEquals("The element should not have a property of quantity",null,(((DBReflexiveModelElement) element).getProps().get("QUANTITY")));
		} 
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}		
}

//Now we need to test that we can delete an object from the database.

@Test public void BasicEOL_DeleteElement_Orders()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
	modelString = ("var a = new ORDERS;delete a;");
	rModel.load();
	EolModule module = new EolModule(); 
	module.parse(modelString);
	module.getContext().getModelRepository().addModel(rModel);
	Object returnValue = module.execute();
	assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ORDERS").size());
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_DeleteElement_Product()
{
	try
	{
	assertEquals("The number of records should be 7 before insert",7,rModel.getAllOfType("PRODUCT").size());
	modelString = ("var a = new PRODUCT;delete a;");
	rModel.load();
	EolModule module = new EolModule(); 
	module.parse(modelString);
	module.getContext().getModelRepository().addModel(rModel);
	Object returnValue = module.execute();
	assertEquals("The number of records should be 7 after insert",7,rModel.getAllOfType("PRODUCT").size());
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	} 
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}		
}

@Test public void BasicEOL_DeleteElement_Customer()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("CUSTOMER").size());
	modelString = ("var a = new CUSTOMER;delete a;");
	rModel.load();
	EolModule module = new EolModule(); 
	module.parse(modelString);
	module.getContext().getModelRepository().addModel(rModel);
	Object returnValue = module.execute();
	assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("CUSTOMER").size());
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}			
}

@Test public void BasicEOL_DeleteElement_Address()
{
	try
	{
	assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
	modelString = ("var a = new ADDRESS;delete a;");
	rModel.load();
	EolModule module = new EolModule(); 
	module.parse(modelString);
	module.getContext().getModelRepository().addModel(rModel);
	Object returnValue = module.execute();
	assertEquals("The number of records should be 4 after insert",4,rModel.getAllOfType("ADDRESS").size());
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}			
}

@Test public void BasicEOL_DeleteElement_OrdersDetail()
{
	try
	{
	assertEquals("The number of records should be 11 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
	modelString = ("var a = new ORDERSDETAIL;delete a;");
	rModel.load();
	EolModule module = new EolModule(); 
	module.parse(modelString);
	module.getContext().getModelRepository().addModel(rModel);
	Object returnValue = module.execute();
	assertEquals("The number of records should be 11 after insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}				
}



//Now we need to test that we can select an object from the database.
@Test public void BasicEOL_SelectElementProperty_AddressAddressId()
{
	try
	{
	assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
	Object element = rModel.createInstance("ADDRESS");
	assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "ADDRESSID");	
	assertEquals("The returned Value should be 4",4,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}				
}
	

@Test public void BasicEOL_SelectElementProperty_AddressStreet()
{
	try
	{
	assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
	Object element = rModel.createInstance("ADDRESS");
	assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "STREET");	
	assertEquals("The returned Value should be null",null,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}			
}

@Test public void BasicEOL_SelectElementProperty_AddressNumberId()
{
	try
	{
	assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
	Object element = rModel.createInstance("ADDRESS");
	assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "NUMBER");	
	assertEquals("The returned Value should be null",null,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_SelectElementProperty_AddressPostCodeId()
{
	try
	{
	assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
	Object element = rModel.createInstance("ADDRESS");
	assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "POSTCODE");	
	assertEquals("The returned Value should be null",null,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
		
}

@Test public void BasicEOL_SelectElementProperty_AddressCountry()
{
	try
	{
	assertEquals("The number of records should be 4 before insert",4,rModel.getAllOfType("ADDRESS").size());
	Object element = rModel.createInstance("ADDRESS");
	assertEquals("The number of records should be 5 after insert",5,rModel.getAllOfType("ADDRESS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "COUNTRY");	
	assertEquals("The returned Value should be null",null,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
		
}

@Test public void BasicEOL_SelectElementProperty_CutomerCustomerId()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("CUSTOMER").size());
	Object element = rModel.createInstance("CUSTOMER");
	assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
	Object value = rModel.getPropertyGetter().invoke(element, "CUSTOMERID");	
	assertEquals("The returned Value should be null",5,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}

@Test public void BasicEOL_SelectElementProperty_CutomerfirstName()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("CUSTOMER").size());
	Object element = rModel.createInstance("CUSTOMER");
	assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
	Object value = rModel.getPropertyGetter().invoke(element, "FIRSTNAME");	
	assertEquals("The returned Value should be null",null,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}

@Test public void BasicEOL_SelectElementProperty_CutomerlastName()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("CUSTOMER").size());
	Object element = rModel.createInstance("CUSTOMER");
	assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
	Object value = rModel.getPropertyGetter().invoke(element, "LASTNAME");	
	assertEquals("The returned Value should be null",null,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}

}

@Test public void BasicEOL_SelectElementProperty_CutomerAddressId()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("CUSTOMER").size());
	Object element = rModel.createInstance("CUSTOMER");
	assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
	Object value = rModel.getPropertyGetter().invoke(element, "ADDRESSID");	
	assertEquals("The returned Value should be null",0,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}

}


@Test public void BasicEOL_SelectElementProperty_OrdersOrderId()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
	Object element = rModel.createInstance("ORDERS");
	assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "ORDERID");	
	assertEquals("The returned Value should be null",5,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}

@Test public void BasicEOL_SelectElementProperty_OrdersCustomerId()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
	Object element = rModel.createInstance("ORDERS");
	assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "CUSTOMERID");	
	assertEquals("The returned Value should be null",0,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}

@Test public void BasicEOL_SelectElementProperty_OrdersDateIssued()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
	Object element = rModel.createInstance("ORDERS");
	assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "DATEISSUED");	
	assertEquals("The returned Value should be null",null,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
	
}

@Test public void BasicEOL_SelectElementProperty_OrdersDelivered()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
	Object element = rModel.createInstance("ORDERS");
	assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "DELIVERED");	
	assertEquals("The returned Value should be null",false,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
	
}

@Test public void BasicEOL_SelectElementProperty_OrdersDeliveryAddressId()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
	Object element = rModel.createInstance("ORDERS");
	assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());
	Object value = rModel.getPropertyGetter().invoke(element, "DELIVERYADDRESSID");	
	assertEquals("The returned Value should be null",0,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}
}

@Test public void BasicEOL_SelectElementProperty_OrdersDetailOrderDetailId()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
	Object element = rModel.createInstance("ORDERSDETAIL");
	assertEquals("The number of records should be 6 after insert",12,rModel.getAllOfType("ORDERSDETAIL").size());
	Object value = rModel.getPropertyGetter().invoke(element, "ORDERDETAILID");	
	assertEquals("The returned Value should be 11",11,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_SelectElementProperty_OrdersDetailOrderId()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
	Object element = rModel.createInstance("ORDERSDETAIL");
	assertEquals("The number of records should be 6 after insert",12,rModel.getAllOfType("ORDERSDETAIL").size());
	Object value = rModel.getPropertyGetter().invoke(element, "ORDERID");	
	assertEquals("The returned Value should be 0",0,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_SelectElementProperty_OrdersDetailProductId()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
	Object element = rModel.createInstance("ORDERSDETAIL");
	assertEquals("The number of records should be 6 after insert",12,rModel.getAllOfType("ORDERSDETAIL").size());
	Object value = rModel.getPropertyGetter().invoke(element, "PRODUCTID");	
	assertEquals("The returned Value should be 0",0,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_SelectElementProperty_OrdersDetailQuantity()
{
	try
	{
	assertEquals("The number of records should be 5 before insert",11,rModel.getAllOfType("ORDERSDETAIL").size());
	Object element = rModel.createInstance("ORDERSDETAIL");
	assertEquals("The number of records should be 6 after insert",12,rModel.getAllOfType("ORDERSDETAIL").size());
	Object value = rModel.getPropertyGetter().invoke(element, "QUANTITY");	
	assertEquals("The returned Value should be 0.0",0.0,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}



@Test public void BasicEOL_SelectElementProperty_ProductProductId()
{
	try
	{
	assertEquals("The number of records should be 7 before insert",7,rModel.getAllOfType("PRODUCT").size());
	Object element = rModel.createInstance("PRODUCT");
	assertEquals("The number of records should be 8 after insert",8,rModel.getAllOfType("PRODUCT").size());
	Object value = rModel.getPropertyGetter().invoke(element, "PRODUCTID");	
	assertEquals("The returned Value should be 7",7,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_SelectElementProperty_ProductName()
{
	try
	{
	assertEquals("The number of records should be 7 before insert",7,rModel.getAllOfType("PRODUCT").size());
	Object element = rModel.createInstance("PRODUCT");
	assertEquals("The number of records should be 8 after insert",8,rModel.getAllOfType("PRODUCT").size());
	Object value = rModel.getPropertyGetter().invoke(element, "NAME");	
	assertEquals("The returned Value should be null",null,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

@Test public void BasicEOL_SelectElementProperty_OrdersUnitPrice()
{
	try
	{
	assertEquals("The number of records should be 7 before insert",7,rModel.getAllOfType("PRODUCT").size());
	Object element = rModel.createInstance("PRODUCT");
	assertEquals("The number of records should be 8 after insert",8,rModel.getAllOfType("PRODUCT").size());
	Object value = rModel.getPropertyGetter().invoke(element, "UNITPRICE");	
	assertEquals("The returned Value should be 0.0",0.0,value);
	}
	catch (EolModelElementTypeNotFoundException e) 
	{
	e.printStackTrace();	
	fail("should not throw an Exception");
	} 
	catch (EolModelLoadingException e) 
    {
		e.printStackTrace();
		fail("should not throw an Exception");
	}                                                                                             
	catch (Exception e)
	{
		e.printStackTrace();
		fail("should not throw an Exception");
	}	
}

//Now we need to test the more intermediate features of the solution

//Create
//There are no advanced creation functionality needed.


//Update
@Test public void BasicEOL_UpdateElementProperty_CustomerForename()
{
	try
	{
assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("CUSTOMER").size());
modelString = ("var a = new CUSTOMER;a.FIRSTNAME=a.CUSTOMERID;");
rModel.load();
EolModule module = new EolModule(); 
module.parse(modelString);
module.getContext().getModelRepository().addModel(rModel);
Object returnValue = module.execute();
assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
//Now see if it has successfully added the correct details to the database.
String statement = "SELECT * FROM EPSILON.EPSILON.CUSTOMER WHERE CUSTOMERID=5";
Statement stmt = Connection.open().createStatement();
ResultSet QuereyResult = stmt.executeQuery(statement);
while (QuereyResult.next())
{
	assertEquals("The CustomerID should be equal to 5",5,QuereyResult.getInt(1));
	assertEquals("The firstname should be equal to null","5",QuereyResult.getString(2));
	assertEquals("The surname should be equal to null",null,QuereyResult.getString(3));
	assertEquals("The AddressID should be equal to 0",0,QuereyResult.getInt(4));			
}
//Now we know the database has been updated we need to test the return value from the DBReflexiveModel createInstance Method().
Object element =  rModel.createInstance("CUSTOMER");
assertEquals("The element should be of type CUSTOMER","CUSTOMER",(((DBReflexiveModelElement) element).getType()));
assertEquals("The element should have an element ID of","6",(((DBReflexiveModelElement) element).getProps().get("CUSTOMERID")));
assertEquals("The element should not have a property of firstName",null,(((DBReflexiveModelElement) element).getProps().get("FIRSTNAME")));
assertEquals("The element should not have a property of surname",null,(((DBReflexiveModelElement) element).getProps().get("SURNAME")));
assertEquals("The element should not have a property of addressID",null,(((DBReflexiveModelElement) element).getProps().get("ADDRESSID")));
}

catch (EolModelElementTypeNotFoundException e) 
{
e.printStackTrace();	
fail("should not throw an Exception");
} 
catch (EolModelLoadingException e) 
{
e.printStackTrace();
fail("should not throw an Exception");
} 
catch (Exception e)
{
e.printStackTrace();
fail("should not throw an Exception");
}
}


//Test Updating a value using a foreign Key relationship.
@Test public void BasicEOL_UpdateElementProperty_FKCustomerFirstName()
{
try
{
System.out.println("You are here");	
assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("CUSTOMER").size());
modelString = ("var a = new CUSTOMER;a.FIRSTNAME=a.FK_Customer_Address.street;");
rModel.load();
EolModule module = new EolModule(); 
module.parse(modelString);
module.getContext().getModelRepository().addModel(rModel);
Object returnValue = module.execute();
assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("CUSTOMER").size());
//Now see if it has successfully added the correct details to the database.
String statement = "SELECT * FROM EPSILON.EPSILON.CUSTOMER WHERE CUSTOMERID=5";
Statement stmt = Connection.open().createStatement();
ResultSet QuereyResult = stmt.executeQuery(statement);
while (QuereyResult.next())
{
	assertEquals("The CustomerID should be equal to 5",5,QuereyResult.getInt(1));
	assertEquals("The firstname should be equal to EPSILON","Epsilon",QuereyResult.getString(2));  //We have not changed the default address so it should get the street from AddressId = 0
	assertEquals("The surname should be equal to null",null,QuereyResult.getString(3));
	assertEquals("The AddressID should be equal to 0",0,QuereyResult.getInt(4));			
}
}
catch (EolModelElementTypeNotFoundException e) 
{
e.printStackTrace();	
fail("should not throw an Exception");
} 
catch (EolModelLoadingException e) 
{
e.printStackTrace();
fail("should not throw an Exception");
} 
catch (Exception e)
{
e.printStackTrace();
fail("should not throw an Exception");
}
}

//Test Updating a value using multiple foreign Key relationships.
@Test public void BasicEOL_UpdateElementProperty_FKCustomerForename()
{
try
{
assertEquals("The number of records should be 5 before insert",5,rModel.getAllOfType("ORDERS").size());
modelString = ("var o = new ORDERS;o.deliveryAddressId=o.FK_Orders_Customer.FK_Customer_Address.AddressId.println();");
rModel.load();
EolModule module = new EolModule(); 
module.parse(modelString);
module.getContext().getModelRepository().addModel(rModel);
Object returnValue = module.execute();
assertEquals("The number of records should be 6 after insert",6,rModel.getAllOfType("ORDERS").size());
//Now see if it has successfully added the correct details to the database.
String statement = "SELECT * FROM EPSILON.EPSILON.ORDERS WHERE ORDERID=5";
Statement stmt = Connection.open().createStatement();
ResultSet QuereyResult = stmt.executeQuery(statement);
while (QuereyResult.next())
{
	assertEquals("The CustomerID should be equal to 5",5,QuereyResult.getInt(1));
	assertEquals("The firstname should be equal to 0","0",QuereyResult.getString(2));  //We have not changed the default address so it should get the street from AddressId = 0
	assertEquals("The surname should be equal to null",null,QuereyResult.getString(3));
	assertEquals("The AddressID should be equal to 0",0,QuereyResult.getInt(4));			
}
}
catch (EolModelElementTypeNotFoundException e) 
{
e.printStackTrace();	
fail("should not throw an Exception");
} 
catch (EolModelLoadingException e) 
{	
e.printStackTrace();
fail("should not throw an Exception");
} 
catch (Exception e)
{
e.printStackTrace();
fail("should not throw an Exception");
}
//Now we need to test the advanced features of the solution.
}








}
